package com.datasync.system.controller;

import java.util.List;
import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.datasync.common.annotation.Log;
import com.datasync.common.core.controller.BaseController;
import com.datasync.common.core.domain.AjaxResult;
import com.datasync.common.enums.BusinessType;
import com.datasync.system.domain.SSyncConfig;
import com.datasync.system.service.ISSyncConfigService;
import com.datasync.common.utils.poi.ExcelUtil;
import com.datasync.common.core.page.TableDataInfo;

/**
 * 同步任务管理Controller
 * 
 * @author zwb
 * @date 2023-04-26
 */
@RestController
@RequestMapping("/system/syncConfig")
public class SSyncConfigController extends BaseController
{
    @Autowired
    private ISSyncConfigService sSyncConfigService;

    /**
     * 查询同步任务管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:syncConfig:list')")
    @GetMapping("/list")
    public TableDataInfo list(SSyncConfig sSyncConfig)
    {
        startPage();
        List<SSyncConfig> list = sSyncConfigService.selectSSyncConfigList(sSyncConfig);
        return getDataTable(list);
    }

    /**
     * 导出同步任务管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:syncConfig:export')")
    @Log(title = "同步任务管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SSyncConfig sSyncConfig)
    {
        List<SSyncConfig> list = sSyncConfigService.selectSSyncConfigList(sSyncConfig);
        ExcelUtil<SSyncConfig> util = new ExcelUtil<SSyncConfig>(SSyncConfig.class);
        util.exportExcel(response, list, "同步任务管理数据");
    }

    /**
     * 获取同步任务管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:syncConfig:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sSyncConfigService.selectSSyncConfigById(id));
    }

    /**
     * 新增同步任务管理
     */
    @PreAuthorize("@ss.hasPermi('system:syncConfig:add')")
    @Log(title = "同步任务管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SSyncConfig sSyncConfig)
    {
        return toAjax(sSyncConfigService.insertSSyncConfig(sSyncConfig));
    }

    /**
     * 修改同步任务管理
     */
    @PreAuthorize("@ss.hasPermi('system:syncConfig:edit')")
    @Log(title = "同步任务管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SSyncConfig sSyncConfig)
    {
        return toAjax(sSyncConfigService.updateSSyncConfig(sSyncConfig));
    }

    /**
     * 删除同步任务管理
     */
    @PreAuthorize("@ss.hasPermi('system:syncConfig:remove')")
    @Log(title = "同步任务管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sSyncConfigService.deleteSSyncConfigByIds(ids));
    }

    /**
     * 启动初始化
     */
    @PostConstruct
    public void init(){
        sSyncConfigService.init();
    }
}
